


window.onload = function () {

    var addmenu = document.getElementById('addmenu')
    var inputFile = document.querySelector('[type="file"]')
    document.querySelector('#img').onclick = function () {
        inputFile.click()
    }
  
document.getElementById('submit').onclick=function(){  
var cais
  if(localStorage['caidan']){
       cais=JSON.parse(localStorage['caidan'])
    }
    else{
        cais=[]
    }
    if(document.getElementById('cd').value !=''){
        var cai=document.getElementById('cd').value
        cais.push({"food":cai})
        localStorage['caidan']=JSON.stringify(cais)
        location.href="user.html"

    }
}

}
function loadFile(inputFile) {
    var fileReader = new FileReader()
    var addtu = document.getElementById('addtu')
    var reg = /^image/gi
    var flag = reg.test(inputFile.files[0].type)
    if (inputFile.files[0].size < Math.pow(1024,2) && flag) {
        fileReader.onload = function (e) {
            document.querySelector('#imgadd').src = e.target.result
        }
        fileReader.readAsDataURL(inputFile.files[0])
        addtu.innerHTML = ''
    } else {
        alert("图片上传失败！")
    }
}
function menuadd(){
    var lastInput = addmenu.lastElementChild.previousElementSibling
    var newCloneInput = lastInput.cloneNode()
    addmenu.appendChild(newCloneInput)
}